local Vector = require('lib.brinevector')
local Flux = require('lib.flux')

local PhState = Class{
_name = "PhState",
init = function (self , velocity, direction, acceleration)
self.velocity = velocity or Vector()
self.direction = direction or Vector()
self.acceleration = acceleration or Vector()
end
}


PhState.start = function (self, unit)
   self.unit = unit
   if not (self.unit) then  error("Assertion failed: self.unit")  end
end

PhState.update = function (self, dt)
   self.last_x, self.last_y = self.unit:get_position()
   self.velocity = Vector(self.unit.x - self.last_x, self.unit.y - self.last_y)
   -- @@INC(self.velocity, self.acceleration)
   -- @@INC(self.unit.x, self.velocity.x)
   -- @@INC(self.unit.y, self.velocity.y)
end

PhState.move = function (self, x, y)
   --@@ASSERT(self.unit.speed_on_road or self.unit.speed_off_road)
   self.unit.timer:tween(2, self.unit, { x = x, y = y },
			 'linear', function () self.unit._path_handler:advance_path() end)
   -- local ox, oy = self.unit:get_position()
   -- self.direction.x = x - ox
   -- self.direction.y = y - oy
   -- self.direction = self.direction.normalized
end

PhState.get_velocity_length = function (self)
   return self.velocity.length
end

return PhState
